<template>
  <div class="discovery-container">
    <!-- 轮播图 -->
    <el-carousel class="" :interval="4000" type="card">
      <el-carousel-item v-for="(item,index) in banners" :key="index">
        <img :src="item.imageUrl" @click="detail(item.url)" />
      </el-carousel-item>
    </el-carousel>
    <!-- 推荐歌单 -->
    <div class="recommend">
      <h3 class="title">
        推荐歌单
      </h3>
      <div class="items">
        <div class="item"v-for="(item,index) in songList" :key="index" @click="toPlayList(item.id)">
          <div class="img-wrap">
            <div class="desc-wrap">
              <span class="desc">{{item.copywriter}}</span>
            </div>
            <img :src="item.picUrl" alt="" />
            <span class="iconfont icon-play"></span>
          </div>
          <p class="name">{{item.name}}</p>
        </div>
      </div>
    </div>
    <!-- 最新音乐 -->
    <div class="news">
      <h3 class="title">
        最新音乐
      </h3>
      <div class="items">
        <div class="item" v-for="(item,index) in songs" :key="index" @dblclick="playSong(item.id)">
          <div class="img-wrap">
            <img :src="item.picUrl" alt="" />
            <span class="iconfont icon-play" @click="playSong(item.id)"></span>
          </div>
          <div class="song-wrap">
            <div class="song-name">{{item.name}}</div>
            <div class="singer">{{item.song.artists[0].name}}</div>
          </div>
        </div>
      </div>
    </div>
    <!-- 推荐MV -->
    <div class="mvs">
      <h3 class="title">推荐MV</h3>
      <div class="items">
        <div class="item" v-for="(item,index) in mvs" :key="index" @click="toMv(item.id)">
          <div class="img-wrap" >
            <img :src="item.picUrl" alt="" />
            <span class="iconfont icon-play"></span>
            <div class="num-wrap">
              <div class="iconfont icon-play"></div>
              <div class="num">{{item.playCount>100000?parseInt(item.playCount/10000)+'万':item.playCount}}</div>
            </div>
          </div>
          <div class="info-wrap">
            <div class="name">{{item.name}}</div>
            <div class="singer">{{item.artistName}}</div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
  import axios from 'axios'
export default {
  name: 'discovery',
  data(){
    return{
      banners:[],
      songList:[],
      songs:[],
      mvs:[]
    }
  },
  created() {  
    // 轮播图
    axios.get('https://autumnfish.cn/banner').then(res=>{
      this.banners=res.data.banners
      // console.log(this.banners)
    })  
    
    // 推荐歌单
    axios({
      url:' https://autumnfish.cn/personalized',
      method:'get',
      params:{
        limit:12
      }
    }).then(res=>{
      // console.log('推荐歌单',res)
      this.songList=res.data.result
    })
    
    // 最新音乐
    axios({
      url:' https://autumnfish.cn/personalized/newsong',
      method:'get'
    }).then(res=>{
      console.log('最新音乐',res)
      this.songs=res.data.result
    })
    
    // 最新MV
    axios({
      url:'https://autumnfish.cn/personalized/mv',
      method:'get'
    }).then(res=>{
      // console.log('最新MV',res)
      this.mvs=res.data.result
    })
  },
  methods:{
    // 没效的方法
    detail(url){
      console.log(url)
    },
    // 播放最新音乐
    playSong(id){
      axios.get('https://autumnfish.cn/song/url?id='+id).then(res=>{
        // console.log(res) //可以获取歌曲对应的播放地址
        // 把获得的播放地址传递给父组件
        this.$parent.musicUrl=res.data.data[0].url
      })
    },
 
    // 歌单详情
    toPlayList(id){
      this.$router.push(`/playlist?q=${id}`)
    },
    // 播放mv
    toMv(id){
      this.$router.push(`/mv?q=${id}`)
    },
  }
};
</script>

<style >

</style>
